<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="Awaken.CodeGen.Controls.TestControl" %>
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Text;

using <%= Assembly %>.Entities;
using NUnit.Framework;

namespace <%= Namespace %>.Tests.Generated
{
    [TestFixture]
    public class <%= Table.ClassName %>GeneratedFixture
    {
        [Test]
        public void VerifyGetAll()
        {
            IList list = <%= Table.ClassName %>.Broker.GetAll();
            Assert.IsNotNull(list);
        }
        
        [Test]
        public void VerifyOneToManys()
        {
            IList list = <%= Table.ClassName %>.Broker.GetAll();
            if( list.Count==0 )
            {
                Assert.Ignore("No Data");
                return;
            }
            
            <%= Table.ClassName %> obj = (<%= Table.ClassName %>)list[0];
            Assert.IsNotNull(obj);
            
            <asp:Repeater ID="oneToManyRepeater" runat="server">
            <ItemTemplate>
            Assert.IsNotNull(obj.<%# Eval("OtherTableCollectionName") %>);
            </ItemTemplate>
            </asp:Repeater>
        }
        
        [Test]
        public void VerifySelectOne()
        {
            string sql = "SELECT TOP 1 * FROM <%= Table.TableName %>";
            
            OleDbConnection conn = new OleDbConnection("<%= ConnectionString %>");

            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = conn;
            cmd.CommandText = sql;
            cmd.CommandType = CommandType.Text;

            OleDbDataAdapter ada = new OleDbDataAdapter(cmd);
                        
            DataSet ds = new DataSet();
            
            conn.Open();
            ada.Fill(ds);
            conn.Close();
            
            if( ds.Tables[0].Rows.Count==0 )
            {
                Assert.Ignore("No Data");
            }
            else
            {
                object id = ds.Tables[0].Rows[0][0];
                <%= Table.ClassName %> obj = (<%= Table.ClassName %>)<%= Table.ClassName %>.Broker.GetByID( id );
                Assert.IsNotNull(obj);
            }
        }
    }
}